<template>
    <div>
        <!-- seach区域 -->
        <div class="seach">
            <span>
                {{$t('riskcontroltype')}}
                <el-input v-model.trim="selRiskForm.typeValue" :placeholder="$t('plsipt')" size="mini"></el-input>
            </span>
            <span class="seachStatus">
                {{$t('sta')}}
                <el-select v-model="selRiskForm.status" :placeholder="$t('plsset')" size="mini">
                    <el-option :label="'-' + $t('plsset') + '-'" :value="null"></el-option>
                    <el-option :label="$t('vlid')" value="VALID"></el-option>
                    <el-option :label="$t('invlid')" value="INVALID"></el-option>
                </el-select>
            </span>
            <el-button type="primary" @click="getRiskList" size="mini" v-preventReClick>{{$t('qury')}}</el-button>
        </div>
        <!-- 内容区域 -->
        <el-card class="cardBox">
            <el-table border style="width: 100%" :data="riskListTab" row-key="id" :tree-props="{children: 'children', hasChildren: 'hasChildren'}" @expand-change="changeSta">
                <el-table-column prop="typeValue" :label="$t('riskcontroltype')" min-width="125">
                </el-table-column>
                <el-table-column :prop="isEn === 0 ? 'riskRuleNameEn' : 'riskRuleName'" :label="$t('rulename')" min-width="142">
                </el-table-column>
                <el-table-column prop="timeLimit" :label="$t('restperiod')" min-width="81">
                </el-table-column>
                <el-table-column prop="timeLimitType" :label="$t('validitytype')" min-width="97">
                </el-table-column>
                <el-table-column prop="riskRuleItemexplain" :label="$t('ruledescription')" min-width="174">
                </el-table-column>
                <el-table-column prop="stopType" :label="$t('blocktype')" min-width="86">
                </el-table-column>
                <el-table-column prop="status" :label="$t('sta')" min-width="86">
                </el-table-column>
                <el-table-column prop="startTime" :label="$t('efftim')" min-width="155">
                </el-table-column>
                <el-table-column prop="endTime" :label="$t('exptim')" min-width="155">
                </el-table-column>
                <el-table-column prop="address" :label="$t('opratn')" width="90" fixed="right">
                    <template slot-scope="scope">
                        <el-link type="primary" @click="showEditRiskType(scope.row)" v-if="scope.row.status !== $t('invlid')">{{$t('mdfy')}}</el-link>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="selRiskForm.pageNum"
                :page-sizes="[10, 15, 20, 30]"
                :page-size="selRiskForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                :pager-count="5">
            </el-pagination>
        </el-card>
        <!-- typeedit -->
        <el-dialog :title="$t('mdfy')" :visible.sync="typeeditDialogVisible" width="30%" @close="typeeditDialogVisibleClosed(typeeditriskTypeForm)" :close-on-click-modal='isOk' :modal-append-to-body="false">
            <el-form :ref="typeeditriskTypeForm" :rules="typeeditRiskRul" :model="typeeditriskTypeForm" label-width="80px" :hide-required-asterisk="true">
                <el-form-item :label="$t('typename')" prop="typeName">
                    <el-input :disabled="true" v-model="typeeditriskTypeForm.typeName" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('typeenname')" prop="typeNameEn">
                    <el-input :disabled="true" v-model="typeeditriskTypeForm.typeNameEn" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('riskcontroltype')" prop="typeValue">
                    <el-input v-model.trim="typeeditriskTypeForm.typeValue" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('sta')" prop="status">
                    <el-select v-model="typeeditriskTypeForm.status" :placeholder="$t('plsset')" class="sellong">
                        <el-option :label="$t('vlid')" value="VALID"></el-option>
                        <el-option :label="$t('invlid')" value="INVALID"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('efftim')" prop="startTime" :placeholder="$t('plsset')">
                    <el-date-picker class="sellong" :placeholder="$t('plsset')" v-model="typeeditriskTypeForm.startTime" type="date" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                </el-form-item>
                <el-form-item :label="$t('exptim')" prop="endTime" :placeholder="$t('plsset')">
                    <el-date-picker class="sellong" :placeholder="$t('plsset')" v-model="typeeditriskTypeForm.endTime" type="date" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="typeeditRiskType(typeeditriskTypeForm)" v-preventReClick>{{$t('cfm')}}</el-button>
                <el-button @click="typeeditDialogVisible = false" v-preventReClick>{{$t('cnl')}}</el-button>
            </span>
        </el-dialog>
        <!-- ruleedit -->
        <el-dialog :title="$t('mdfy')" :visible.sync="ruleeditDialogVisible" width="30%" @close="ruleeditDialogVisibleClosed(ruleeditriskTypeForm)" :close-on-click-modal='isOk' :modal-append-to-body="false">
            <el-form :ref="ruleeditriskTypeForm" :rules="ruleeditRiskRul" :model="ruleeditriskTypeForm" label-width="80px" :hide-required-asterisk="true">
                <el-form-item :label="$t('rulename')" prop="riskRuleName">
                    <el-input :disabled="true" v-model="ruleeditriskTypeForm.riskRuleName" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('ruleenname')" prop="riskRuleNameEn">
                    <el-input :disabled="true" v-model="ruleeditriskTypeForm.riskRuleNameEn" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('rulekey')" prop="riskRuleKey">
                    <el-input v-model.trim="ruleeditriskTypeForm.riskRuleKey" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('sta')" prop="status">
                    <el-select v-model="ruleeditriskTypeForm.status" :placeholder="$t('plsset')" class="sellong">
                        <el-option :label="$t('vlid')" value="VALID"></el-option>
                        <el-option :label="$t('invlid')" value="INVALID"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('sort')" prop="sort" :placeholder="$t('plsset')">
                    <el-input v-model.trim="ruleeditriskTypeForm.sort" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('efftim')" prop="startTime" :placeholder="$t('plsset')">
                    <el-date-picker class="sellong" :placeholder="$t('plsset')" v-model="ruleeditriskTypeForm.startTime" type="date" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                </el-form-item>
                <el-form-item :label="$t('exptim')" prop="endTime" :placeholder="$t('plsset')">
                    <el-date-picker class="sellong" :placeholder="$t('plsset')" v-model="ruleeditriskTypeForm.endTime" type="date" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                </el-form-item>
                <el-form-item :label="$t('riskcontroltype')" prop="riskTypeId">
                    <el-input :disabled="true" v-model="ruleeditriskTypeForm.riskTypeId" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="editRiskType(ruleeditriskTypeForm)">{{$t('cfm')}}</el-button>
                <el-button @click="ruleeditDialogVisible = false">{{$t('cnl')}}</el-button>
            </span>
        </el-dialog>
        <!-- itemedit -->
        <el-dialog :title="$t('mdfy')" :visible.sync="itemeditDialogVisible" width="30%" @close="itemeditDialogVisibleClosed(itemeditriskTypeForm)" :close-on-click-modal='isOk' :modal-append-to-body="false">
            <el-form :ref="itemeditriskTypeForm" :rules="itemeditRiskRul" :model="itemeditriskTypeForm" label-width="80px" :hide-required-asterisk="true">
                <el-form-item :label="$t('ruleitemname')" prop="riskRuleItemName">
                    <el-input :disabled="true" v-model.trim="itemeditriskTypeForm.riskRuleItemName" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('ruleitemenname')" prop="riskRuleItemNameEn">
                    <el-input :disabled="true" v-model.trim="itemeditriskTypeForm.riskRuleItemNameEn" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('triggercondition')" required v-if="isSymbol === 1">
                    <el-row :gutter="10">
                        <el-col :span="6">
                            <el-input :disabled="true" class="specialc" v-model.trim="itemeditriskTypeForm.riskRuleItemKey" :placeholder="$t('plsipt')"></el-input>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item prop="riskRuleItemValue1">
                                <el-input class="specialc" v-model.trim="itemeditriskTypeForm.riskRuleItemValue1" :placeholder="$t('plsipt')" prop="riskRuleItemValue1"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-input :disabled="true" class="specialc" v-model.trim="itemeditriskTypeForm.riskRuleItemKey" :placeholder="$t('plsipt')" prop="riskRuleItemValue2"></el-input>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item prop="riskRuleItemValue2">
                                <el-input class="specialc" v-model.trim="itemeditriskTypeForm.riskRuleItemValue2" :placeholder="$t('plsipt')"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form-item>
                <el-form-item :label="$t('triggercondition')" required v-if="isSymbol === 0">
                    <el-col :span="20">
                        <el-input :disabled="true" class="special" v-model.trim="itemeditriskTypeForm.riskRuleItemKey" :placeholder="$t('plsipt')"></el-input>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item prop="riskRuleItemValue">
                            <el-input class="special" v-model.trim="itemeditriskTypeForm.riskRuleItemValue" :placeholder="$t('plsipt')"></el-input>
                        </el-form-item>
                    </el-col>
                </el-form-item>
                <el-form-item :label="$t('restperiod')" prop="timeLimit">
                    <el-input v-model.trim="itemeditriskTypeForm.timeLimit" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('validitytype')" prop="timeLimitType">
                    <el-input :disabled="true" v-model.trim="itemeditriskTypeForm.timeLimitType" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('sort')" prop="sort">
                    <el-input v-model.trim="itemeditriskTypeForm.sort" :placeholder="$t('plsipt')"></el-input>
                </el-form-item>
                <el-form-item :label="$t('blocktype')" prop="stopType">
                    <el-select v-model="itemeditriskTypeForm.stopType" :placeholder="$t('plsset')" class="sellong">
                        <el-option label="STOP" value="STOP"></el-option>
                        <el-option label="WARN" value="WARN"></el-option>
                        <el-option label="CONTINUE" value="CONTINUE"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('sta')" prop="status">
                    <el-select v-model="itemeditriskTypeForm.status" :placeholder="$t('plsset')" class="sellong">
                        <el-option :label="$t('vlid')" value="VALID"></el-option>
                        <el-option :label="$t('invlid')" value="INVALID"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('efftim')" prop="startTime" :placeholder="$t('plsset')">
                    <el-date-picker class="sellong" :placeholder="$t('plsset')" v-model="itemeditriskTypeForm.startTime" type="date" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                </el-form-item>
                <el-form-item :label="$t('exptim')" prop="endTime" :placeholder="$t('plsset')">
                    <el-date-picker class="sellong" :placeholder="$t('plsset')" v-model="itemeditriskTypeForm.endTime" type="date" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="itemeditRiskType(itemeditriskTypeForm)" v-preventReClick>{{$t('cfm')}}</el-button>
                <el-button @click="itemeditDialogVisible = false" v-preventReClick>{{$t('cnl')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import Cookies from 'js-cookie'
import {
    getrisktypelist,
    addrisktype,
    updaterisktype,
    getriskrulelist,
    getriskitemlist,
    updateriskrule,
    updateriskitem
} from '@/libs/reqlist.js'
export default {
    data () {
        var isNumberVlidator = (rule, value, callback) => {
            var pattern = /^([0-9]{1,3})?$/
            if (!pattern.test(value)) {
                return callback(new Error(this.$t('plsentnothrdig')))
            } else {
                callback()
            }
        }
        var isNumber = (rule, value, callback) => {
            var pattern = /(^[0-9]\d*$)/
            if (!pattern.test(value)) {
                return callback(new Error(this.$t('plsentasignnum')))
            } else {
                callback()
            }
        }
        var isBig = (rule, value, callback) => {
            if (this.itemeditriskTypeForm.riskRuleItemValue1 > this.itemeditriskTypeForm.riskRuleItemValue2) {
                return callback(new Error(this.$t('plsenttheminval')))
            } else {
                callback()
            }
        }
        return {
            isSymbol: 0,
            isEn: 1,
            isOk: false,
            total: 0,
            createTime: null,
            selRiskForm: {
                orderParamIdx: 0,
                orderType: null,
                pageNum: 1,
                pageSize: 10,
                status: null,
                typeName: null,
                typeValue: null
            },
            riskListTab: [],
            typeaddDialogVisible: false,
            typeaddriskTypeForm: {
                endTime: null,
                startTime: null,
                status: null,
                sysType: 'MHSB_PSN',
                typeName: null,
                typeNameEn: null,
                typeValue: null
            },
            typeaddRiskRul: {
                typeName: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                typeNameEn: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                typeValue: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                status: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                startTime: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                endTime: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ]
            },
            typeeditRiskRul: {
                typeName: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                typeNameEn: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                typeValue: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                status: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                startTime: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                endTime: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ]
            },
            typeeditDialogVisible: false,
            editId: '',
            typeeditriskTypeForm: {
                endTime: null,
                startTime: null,
                status: null,
                sysType: 'MHSB_PSN',
                typeName: null,
                typeNameEn: null,
                typeValue: null
            },
            fakeid: 1,
            ruleeditRiskRul: {
                riskRuleName: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                riskRuleNameEn: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                riskRuleKey: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                status: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                sort: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' },
                    { validator: isNumberVlidator, trigger: 'blur' }
                ],
                startTime: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                endTime: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ]
            },
            ruleeditDialogVisible: false,
            ruleeditriskTypeForm: {
                startTime: null,
                endTime: null,
                riskRuleKey: null,
                riskRuleName: null,
                riskRuleNameEn: null,
                riskTypeId: null,
                sort: null,
                status: null
            },
            itemeditRiskRul: {
                riskRuleItemName: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                riskRuleItemNameEn: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                riskRuleItemKey: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                riskRuleItemValue1: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' },
                    { validator: isBig, trigger: 'blur' },
                    { validator: isNumber, trigger: 'blur' }
                ],
                riskRuleItemValue2: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' },
                    { validator: isNumber, trigger: 'blur' }
                ],
                riskRuleItemValue: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' },
                    { validator: isNumber, trigger: 'blur' }
                ],
                riskOrder: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                sort: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' },
                    { validator: isNumberVlidator, trigger: 'blur' }
                ],
                stopType: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                status: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                startTime: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                endTime: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ],
                timeLimit: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' },
                    { validator: isNumber, trigger: 'blur' }
                ],
                timeLimitType: [
                    { required: true, message: this.$t('cantbeemt'), trigger: 'blur' }
                ]
            },
            itemeditDialogVisible: false,
            itemeditriskTypeForm: {
                startTime: null,
                endTime: null,
                riskOrder: null,
                riskRuleId: null,
                riskRuleItemKey: null,
                riskRuleItemName: null,
                riskRuleItemNameEn: null,
                riskRuleItemValue: null,
                sort: null,
                status: null,
                stopType: null,
                timeLimit: 0,
                timeLimitType: null,
                riskRuleItemValue1: null,
                riskRuleItemValue2: null
            }
        }
    },
    methods: {
        selectRiskList () {
            getrisktypelist(JSON.stringify(this.selRiskForm)).then(async(res) => {
                if (res.data.code === '000000') {
                    this.total = res.data.data.total - 0
                    let j = res.data.data.list
                    for (let i = 0; i <= j.length - 1; i++) {
                        j[i].children = []
                        let item = j[i]
                        item.id = this.fakeid++
                        if (item.status === 'VALID') {
                            item.status = this.$t('vlid')
                            item.children = [
                                { id: this.fakeid++ }
                            ]
                        }
                        if (item.status === 'INVALID') item.status = this.$t('invlid')
                    }
                    this.riskListTab = res.data.data.list
                }
            })
        },
        async changeSta (expandedRows) {
            if (expandedRows.children !== null) {
                let rst = null
                if (!expandedRows.riskTypeRuleId) {
                    rst = await getriskrulelist(expandedRows.riskTypeId)
                } else {
                    rst = await getriskitemlist(expandedRows.riskTypeRuleId)
                }
                if (rst.data.code === '000000') {
                    // search  thirdly
                    let d = rst.data.data
                    for (let k = 0; k <= d.length - 1; k++) {
                        d[k].children = []
                        let nape = d[k]
                        nape.id = this.fakeid++
                        if (nape.status === 'VALID') {
                            nape.status = this.$t('vlid')
                            if (!nape.riskRuleItemId) {
                                nape.children = [
                                    { id: this.fakeid++ }
                                ]
                            }
                        }
                        if (nape.status === 'INVALID') nape.status = this.$t('invlid')
                        if (nape.riskRuleItemId) {
                            delete nape.riskRuleName
                            // nape.riskRuleItemValue = nape.riskRuleItemValueSymbol + nape.riskRuleItemValue
                            // 处理固定区间数据
                            if (nape.riskRuleItemValue.indexOf('&&') !== -1) {
                                let chararr = nape.riskRuleItemValue.split('&&')
                                // 添加标识
                                nape.symbol = '&&'
                                nape.riskRuleItemValue1 = (chararr[0].split('>'))[1].trim()
                                nape.riskRuleItemValue2 = (chararr[1].split('<'))[1].trim()
                                nape.riskRuleItemexplain = nape.riskRuleItemName + '>' + nape.riskRuleItemValue1 + '且' + '<' + nape.riskRuleItemValue2
                            } else {
                                if (nape.riskRuleItemValue.indexOf('>') !== -1) {
                                    // 处理大于区间数据
                                    nape.riskRuleItemValue = nape.riskRuleItemValue.split('>')[1]
                                    nape.riskRuleItemValueSymbol = '>'
                                    nape.riskRuleItemexplain = nape.riskRuleItemName + '>' + nape.riskRuleItemValue
                                }
                                if (nape.riskRuleItemValue.indexOf('<') !== -1) {
                                    // 处理小于区间数据
                                    nape.riskRuleItemValue = nape.riskRuleItemValue.split('<')[1]
                                    nape.riskRuleItemValueSymbol = '<'
                                    nape.riskRuleItemexplain = nape.riskRuleItemName + '<' + nape.riskRuleItemValue
                                }
                            }
                            if (nape.timeLimitType === 'H') nape.timeLimitType = this.$t('hour')
                            if (nape.timeLimitType === 'M') nape.timeLimitType = this.$t('minute')
                        }
                    }
                    expandedRows.children = rst.data.data
                }
            }
        },
        getRiskList () {
            this.selRiskForm.pageNum = 1
            this.selectRiskList()
        },
        handleSizeChange (newSize) {
            this.selRiskForm.pageSize = newSize
            this.selectRiskList()
        },
        // 监听总页数变化
        handleCurrentChange (newNum) {
            this.selRiskForm.pageNum = newNum
            this.selectRiskList()
        },
        showEditRiskType (data) {
            // 一级修改
            if (data.sysType) {
                this.typeeditriskTypeForm.endTime = data.endTime
                this.typeeditriskTypeForm.startTime = data.startTime
                this.typeeditriskTypeForm.status = data.status
                if (this.typeeditriskTypeForm.status === this.$t('vlid')) this.typeeditriskTypeForm.status = 'VALID'
                if (this.typeeditriskTypeForm.status === this.$t('invlid')) this.typeeditriskTypeForm.status = 'INVALID'
                this.typeeditriskTypeForm.typeName = data.typeName
                this.typeeditriskTypeForm.typeNameEn = data.typeNameEn
                this.typeeditriskTypeForm.typeValue = data.typeValue
                this.editId = data.riskTypeId
                this.typeeditDialogVisible = true
            }
            if (data.riskTypeRuleId) {
                // 二级修改
                this.ruleeditriskTypeForm.startTime = data.startTime
                this.ruleeditriskTypeForm.endTime = data.endTime
                this.ruleeditriskTypeForm.riskRuleName = data.riskRuleName
                this.ruleeditriskTypeForm.riskRuleKey = data.riskRuleKey
                this.ruleeditriskTypeForm.riskRuleNameEn = data.riskRuleNameEn
                this.ruleeditriskTypeForm.typeNameEn = data.typeNameEn
                this.ruleeditriskTypeForm.sort = data.sort
                this.ruleeditriskTypeForm.status = data.status
                if (this.ruleeditriskTypeForm.status === this.$t('vlid')) this.ruleeditriskTypeForm.status = 'VALID'
                if (this.ruleeditriskTypeForm.status === this.$t('invlid')) this.ruleeditriskTypeForm.status = 'INVALID'
                this.ruleeditriskTypeForm.riskTypeId = data.riskTypeId
                this.editId = data.riskTypeRuleId
                this.ruleeditDialogVisible = true
            }
            if (data.riskRuleItemId) {
                // 三级修改
                this.itemeditriskTypeForm.endTime = data.endTime
                this.itemeditriskTypeForm.startTime = data.startTime
                this.itemeditriskTypeForm.status = data.status
                this.itemeditriskTypeForm.riskOrder = data.riskOrder
                this.itemeditriskTypeForm.riskRuleId = data.riskRuleId - 0
                this.itemeditriskTypeForm.riskRuleItemKey = data.riskRuleItemKey
                this.itemeditriskTypeForm.riskRuleItemName = data.riskRuleItemName
                this.itemeditriskTypeForm.riskRuleItemNameEn = data.riskRuleItemNameEn
                this.itemeditriskTypeForm.timeLimit = data.timeLimit
                this.itemeditriskTypeForm.sort = data.sort
                this.itemeditriskTypeForm.stopType = data.stopType
                this.itemeditriskTypeForm.timeLimitType = data.timeLimitType
                this.editId = data.riskRuleItemId
                // 修改状态
                if (this.itemeditriskTypeForm.status === this.$t('vlid')) this.itemeditriskTypeForm.status = 'VALID'
                if (this.itemeditriskTypeForm.status === this.$t('invlid')) this.itemeditriskTypeForm.status = 'INVALID'
                // 判断是否为固定区间数据
                if (data.symbol) {
                    this.itemeditriskTypeForm.symbol = data.symbol
                    if (data.riskRuleItemValue1.indexOf('=') !== -1) {
                        this.itemeditriskTypeForm.riskRuleItemValue1 = (data.riskRuleItemValue1.split('='))[1]
                        this.itemeditriskTypeForm.equalssign1 = '='
                    } else {
                        this.itemeditriskTypeForm.riskRuleItemValue1 = data.riskRuleItemValue1
                    }
                    if (data.riskRuleItemValue2.indexOf('=') !== -1) {
                        this.itemeditriskTypeForm.riskRuleItemValue2 = (data.riskRuleItemValue2.split('='))[1]
                        this.itemeditriskTypeForm.equalssign2 = '='
                    } else {
                        this.itemeditriskTypeForm.riskRuleItemValue2 = data.riskRuleItemValue2
                    }
                    this.isSymbol = 1
                } else {
                    // 给数据添加本来的符号
                    if (data.riskRuleItemValueSymbol) this.itemeditriskTypeForm.riskRuleItemValueSymbol = data.riskRuleItemValueSymbol
                    // 判断数据是否包含‘=’
                    if (data.riskRuleItemValue.indexOf('=') !== -1) {
                        this.itemeditriskTypeForm.equalsign = '='
                        this.itemeditriskTypeForm.riskRuleItemValue = (data.riskRuleItemValue.split('='))[1]
                    } else {
                        this.itemeditriskTypeForm.riskRuleItemValue = data.riskRuleItemValue
                    }
                    this.isSymbol = 0
                }
                this.itemeditDialogVisible = true
            }
        },
        // 一级修改及关联修改框的关闭
        typeeditRiskType () {
            updaterisktype(JSON.stringify(this.typeeditriskTypeForm), this.editId).then(res => {
                if (res.data.code === '000000') {
                    this.$message({
                        message: this.$t('modfunsuc'),
                        type: 'success'
                    })
                    this.selectRiskList()
                    this.typeeditDialogVisible = false
                }
            })
        },
        typeeditDialogVisibleClosed (form) {
            this.$refs[form].resetFields()
        },
        // 二级修改及关联修改框的关闭
        editRiskType () {
            updateriskrule(JSON.stringify(this.ruleeditriskTypeForm), this.editId).then(res => {
                if (res.data.code === '000000') {
                    this.$message({
                        message: this.$t('modfunsuc'),
                        type: 'success'
                    })
                    this.selectRiskList()
                    this.ruleeditDialogVisible = false
                }
            })
        },
        ruleeditDialogVisibleClosed (form) {
            this.$refs[form].resetFields()
        },
        // 三级修改及关联修改框的关闭
        itemeditRiskType (form) {
            this.$refs[form].validate(valid => {
                if (!valid) return
                // 替换有效期类型
                if (this.itemeditriskTypeForm.timeLimitType === this.$t('hour')) this.itemeditriskTypeForm.timeLimitType = 'H'
                if (this.itemeditriskTypeForm.timeLimitType === this.$t('minute')) this.itemeditriskTypeForm.timeLimitType = 'M'
                // 构建规则项内容
                if (this.itemeditriskTypeForm.symbol) {
                    if (!this.itemeditriskTypeForm.equalssign1 && !this.itemeditriskTypeForm.equalssign2) {
                        this.itemeditriskTypeForm.riskRuleItemValue = this.itemeditriskTypeForm.riskRuleItemKey + '>' + this.itemeditriskTypeForm.riskRuleItemValue1 + this.itemeditriskTypeForm.symbol + this.itemeditriskTypeForm.riskRuleItemKey + '<' + this.itemeditriskTypeForm.riskRuleItemValue2
                        delete this.itemeditriskTypeForm.symbol
                    }
                    if (this.itemeditriskTypeForm.equalssign1 && this.itemeditriskTypeForm.equalssign2) {
                        this.itemeditriskTypeForm.riskRuleItemValue = this.itemeditriskTypeForm.riskRuleItemKey + this.itemeditriskTypeForm.equalssign1 + '>' + this.itemeditriskTypeForm.riskRuleItemValue1 + this.itemeditriskTypeForm.symbol + this.itemeditriskTypeForm.riskRuleItemKey + '<' + this.itemeditriskTypeForm.equalssign2 + this.itemeditriskTypeForm.riskRuleItemValue2
                        delete this.itemeditriskTypeForm.symbol
                        delete this.itemeditriskTypeForm.equalssign1
                        delete this.itemeditriskTypeForm.equalssign2
                    }
                    if (!this.itemeditriskTypeForm.equalssign1 && this.itemeditriskTypeForm.equalssign2) {
                        this.itemeditriskTypeForm.riskRuleItemValue = this.itemeditriskTypeForm.riskRuleItemKey + '>' + this.itemeditriskTypeForm.riskRuleItemValue1 + this.itemeditriskTypeForm.symbol + this.itemeditriskTypeForm.riskRuleItemKey + '<' + this.itemeditriskTypeForm.equalssign2 + this.itemeditriskTypeForm.riskRuleItemValue2
                        delete this.itemeditriskTypeForm.symbol
                        delete this.itemeditriskTypeForm.equalssign2
                    }
                    if (!this.itemeditriskTypeForm.equalssign2 && this.itemeditriskTypeForm.equalssign1) {
                        this.itemeditriskTypeForm.riskRuleItemValue = this.itemeditriskTypeForm.riskRuleItemKey + this.itemeditriskTypeForm.equalssign1 + '>' + this.itemeditriskTypeForm.riskRuleItemValue1 + this.itemeditriskTypeForm.symbol + this.itemeditriskTypeForm.riskRuleItemKey + '<' + this.itemeditriskTypeForm.riskRuleItemValue2
                        delete this.itemeditriskTypeForm.symbol
                        delete this.itemeditriskTypeForm.equalssign1
                    }
                } else {
                    if (this.itemeditriskTypeForm.riskRuleItemValueSymbol && this.itemeditriskTypeForm.equalsign) {
                        this.itemeditriskTypeForm.riskRuleItemValue = this.itemeditriskTypeForm.riskRuleItemKey + this.itemeditriskTypeForm.riskRuleItemValueSymbol + this.itemeditriskTypeForm.equalsign + this.itemeditriskTypeForm.riskRuleItemValue
                        delete this.itemeditriskTypeForm.riskRuleItemValueSymbol
                        delete this.itemeditriskTypeForm.equalsign
                    } else {
                        this.itemeditriskTypeForm.riskRuleItemValue = this.itemeditriskTypeForm.riskRuleItemKey + this.itemeditriskTypeForm.riskRuleItemValueSymbol + this.itemeditriskTypeForm.riskRuleItemValue
                        delete this.itemeditriskTypeForm.riskRuleItemValueSymbol
                    }
                }
                delete this.itemeditriskTypeForm.riskRuleItemValue1
                delete this.itemeditriskTypeForm.riskRuleItemValue2
                this.itemeditriskTypeForm.timeLimit = this.itemeditriskTypeForm.timeLimit - 0
                updateriskitem(JSON.stringify(this.itemeditriskTypeForm), this.editId).then(res => {
                    if (res.data.code === '000000') {
                        this.$message({
                            message: this.$t('modfunsuc'),
                            type: 'success'
                        })
                        this.itemeditDialogVisible = false
                        this.selectRiskList()
                    }
                })
            })
        },
        itemeditDialogVisibleClosed (form) {
            this.$refs[form].resetFields()
            this.itemeditriskTypeForm = {
                startTime: null,
                endTime: null,
                riskOrder: null,
                riskRuleId: null,
                riskRuleItemKey: null,
                riskRuleItemName: null,
                riskRuleItemNameEn: null,
                riskRuleItemValue: null,
                sort: null,
                status: null,
                stopType: null,
                timeLimit: 0,
                timeLimitType: null,
                riskRuleItemValue1: null,
                riskRuleItemValue2: null
            }
        }
    },
    mounted () {
        if (Cookies.get('language') === 'zh') this.isEn = 1
        if (Cookies.get('language') === 'en') this.isEn = 0
        this.selectRiskList()
    }
}
</script>

<style lang="less" scoped>
@import './risktypelist.less';
</style>
